scaling.min.max <- function(data, min = 0, max = 1){
  # This function is borrowed from Francis Hsu's testOTM package written for Ghosal & Sen [2021].
  # It scales the data into [0,1]x[0,1], preparing it for the semi discrete solver
  data = scale(data,
               center = apply(as.matrix(data), 2, min, na.rm = TRUE),
               scale = diff(apply(as.matrix(data), 2, range, na.rm = TRUE)))
  data = data * (max - min) + min
  return(data)
}